﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;

using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DevicesView.UCControl
{
    /// <summary>
    /// UCMaxAndMin.xaml 的交互逻辑
    /// </summary>
    public partial class UCMaxAndMin : System.Windows.Controls.UserControl, INotifyPropertyChanged
    {
        public UCMaxAndMin()
        {
            InitializeComponent();
        }
        private object val;
        public object Values
        {
            get => val; set

            {
                val = value;
                if (this.PropertyChanged != null)
                    this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Values"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            double[] mvm = (double[])Values;
            double start = mvm[0] - mvm[2] + mvm[0];
            double end = mvm[2] - mvm[0] + mvm[2];
            double value = end - start / 200 + mvm[1];
            if (value < 0)
                value = 0;
            if (value > 200 - 4)
                value = 200 - 4;
            if (mvm[1] >= start)
                borderValue.Background = Brushes.Green;
            if (mvm[1] >= mvm[2])
                borderValue.Background = Brushes.Red;
            borderValue.Margin = new Thickness(value, 0, 0, 0);
        }

    }
}
